//==============================================================================================
/**
 * @file	d_nohara.c
 * @brief	デバックソース
 * @author	Satoshi Nohara
 * @date	2005.07.26
 */
//==============================================================================================
#include "common.h"
#include "system/lib_pack.h"
#include "system/bmp_list.h"
#include "system/fontproc.h"
#include "system/pm_str.h"
#include "system/get_text.h"

#include "system/snd_tool.h"
#include "system/snd_perap.h"

#include "system/savedata.h"
#include "savedata/mystatus.h"
#include "savedata/zukanwork.h"
#include "savedata\battle_rec.h"
#include "savedata\frontier_savedata.h"
#include "savedata\frontier_ex.h"
#include "savedata\factory_savedata.h"
#include "savedata\stage_savedata.h"
#include "savedata\castle_savedata.h"
#include "savedata\roulette_savedata.h"

#include "fld_bgm.h"
#include "poketool/monsno.h"
#include "fieldmap.h"
#include "fieldsys.h"
#include "field_subproc.h"
#include "field_encount.h"
#include "field_battle.h"
#include "fld_bmp.h"
#include "mapdefine.h"						//ZONE_ID_C01
#include "script.h"							//EventSet_Script
#include "scr_tool.h"
#include "ev_mapchange.h"					//

#include "sysflag.h"
#include "syswork.h"

#include "btl_searcher.h"

#include "msgdata/msg.naix"
#include "msgdata/msg_debug_nohara.h"

//#include "..\fielddata\script\t01r0202_def.h"		//SCRID_TRAINER_MOVE_SCRIPT		//070420無効化
#include "..\fielddata\script\common_scr_def.h"		//SCRID_TRAINER_MOVE_SCRIPT
#include "..\fielddata\script\connect_def.h"		//SCRID_CONNECT_COLOSSEUM
#include "..\fielddata\script\trainer_def.h"		//SCRID_TANPAN_01
//#include "..\fielddata\script\r201_def.h"			//SCRID_R201_FLAG_CHANGE		//070420無効化
#include "..\fielddata\script\hiden_def.h"			//SCRID_R201_FLAG_CHANGE
#include "..\fielddata\script\con_reception_def.h"	//
#include "..\fielddata\script\pc_ug_def.h"	//
#include "..\fielddata\script\perap_def.h"	//
#include "..\fielddata\script\debug_scr_def.h"	//

#include "itemtool/myitem.h"
#include "itemtool/itemsym.h"

#include "../frontier/factory_def.h"
#include "../frontier/castle_def.h"
#include "../frontier/stage_def.h"
#include "../frontier/roulette_def.h"

#include "field/situation.h"
#include "situation_local.h"
#include "field_poketch.h"

//==============================================================================================
//
//	定義
//
//==============================================================================================
#define D_NOHARA_BMPWIN_MAX	(1)				//BMPウィンドウデータ最大数

typedef void (*voidFunc)(void* func);		//関数ポインタ型


//==============================================================================================
//
//	変数
//
//==============================================================================================
static NNSSndCaptureOutputEffectType stereo_mono = NNS_SND_CAPTURE_OUTPUT_EFFECT_NORMAL;

//static s16 d_buf[ 32*100 ] ATTRIBUTE_ALIGN(32);	//波形格納バッファ(何かの企画？)


//==============================================================================================
//
//	デバック構造体
//
//==============================================================================================
typedef struct{
	u8	seq;										//処理ナンバー
	u8	wave_buf_flag:1;							//波形格納バッファを確保したフラグ
	u8	waveout_flag:1;								//鳴き声再生中フラグ
	u8	play_flag:6;								//再生中フラグ
	s16 work;										//汎用ワーク

	int friend_work;								//何番目の友達か

	u8	fro_type;
	u8	btl_type;
	u8	fro_seq;
	u8	fro_add;

	u16 list_bak;									//リスト位置バックアップ
	u16 cursor_bak;									//カーソル位置バックアップ

	u32 sel;
	u32 count;										//カウンター
	u32 count2;										//カウンター

	FIELDSYS_WORK* fsys;							//

	GF_BGL_BMPWIN bmpwin[D_NOHARA_BMPWIN_MAX];		//BMPウィンドウデータ
	BMPLIST_WORK* lw;								//BMPリストデータ

	BMPLIST_DATA* menulist;							//

//	s16* wave_buf;									//波形格納バッファのポインタ

	//STRBUF* msg_buf[EV_WIN_MENU_MAX];				//メッセージデータのポインタ
	MSGDATA_MANAGER* msgman;						//メッセージマネージャー
	WORDSET* wordset;								//単語セット

	void* factory_call;								//ファクトリー呼び出し
}D_NOHARA_WORK;


//==============================================================================================
//
//	プロトタイプ宣言
//
//==============================================================================================
void DebugNoharaMenuInit( FIELDSYS_WORK* fsys );

static void DebugNoharaMenuMain( TCB_PTR tcb, void * work );
static void TcbBmpDel( TCB_PTR tcb, void * work );
static void BmpDel( TCB_PTR tcb );
static void NumMsgSet( D_NOHARA_WORK* wk, GF_BGL_BMPWIN* win, int num, u8 x, u8 y );

void DebugBgmMenuInit( FIELDSYS_WORK* fsys );
void DebugScriptMenuInit( FIELDSYS_WORK* fsys );

static void Debug_StageScr_TypeLevelRecordSet( SAVEDATA* sv, u8 type, u8 csr_pos );

static void D_Nohara_01( TCB_PTR tcb, void * work );
static void D_Nohara_02( TCB_PTR tcb, void * work );
static void D_Nohara_04( TCB_PTR tcb, void * work );
static void D_Nohara_05( TCB_PTR tcb, void * work );
static void D_Nohara_06( TCB_PTR tcb, void * work );
static void D_Nohara_07( TCB_PTR tcb, void * work );
static void D_Nohara_08( TCB_PTR tcb, void * work );
static void D_Nohara_11( TCB_PTR tcb, void * work );
static void D_Nohara_14( TCB_PTR tcb, void * work );
static void D_Nohara_15( TCB_PTR tcb, void * work );
static void D_Nohara_17( TCB_PTR tcb, void * work );
static void D_Nohara_18( TCB_PTR tcb, void * work );
static void D_Nohara_19( TCB_PTR tcb, void * work );
static void D_Nohara_21( TCB_PTR tcb, void * work );
static void D_Nohara_22( TCB_PTR tcb, void * work );
static void D_Nohara_25( TCB_PTR tcb, void * work );
static void D_Nohara_26( TCB_PTR tcb, void * work );
static void D_Nohara_27( TCB_PTR tcb, void * work );
static void D_Nohara_34( TCB_PTR tcb, void * work );
static void D_Nohara_41( TCB_PTR tcb, void * work );


//==============================================================================================
//
//	リストデータ
//
//==============================================================================================
static const struct{
	u32  str_id;
	u32  param;
}DebugMenuList[] = {
	{ msg_debug_nohara_21, (u32)D_Nohara_21 },		//デバックジャンプ
	{ msg_debug_nohara_27, (u32)D_Nohara_27 },		//ゲームボーイ切り替え
	{ msg_debug_nohara_01, (u32)D_Nohara_01 },
//	{ msg_debug_nohara_02, (u32)D_Nohara_02 },
	{ msg_debug_nohara_04, (u32)D_Nohara_04 },
	{ msg_debug_nohara_05, (u32)D_Nohara_05 },
//	{ msg_debug_nohara_06, (u32)D_Nohara_06 },
	{ msg_debug_nohara_07, (u32)D_Nohara_07 },
	{ msg_debug_nohara_08, (u32)D_Nohara_08 },
	{ msg_debug_nohara_11, (u32)D_Nohara_11 },
//	{ msg_debug_nohara_14, (u32)D_Nohara_14 },
	{ msg_debug_nohara_15, (u32)D_Nohara_15 },		//波形テスト
	{ msg_debug_nohara_17, (u32)D_Nohara_17 },		//バッジフラグセット
	{ msg_debug_nohara_18, (u32)D_Nohara_18 },		//隠しアイテムリスト
	{ msg_debug_nohara_19, (u32)D_Nohara_19 },		//キャプチャチェック
	{ msg_debug_nohara_22, (u32)D_Nohara_22 },		//ポケッチ波形テスト
	{ msg_debug_nohara_34, (u32)D_Nohara_34 },		//フロンティア連勝数操作
	{ msg_debug_nohara_41, (u32)D_Nohara_41 },		//ステージ連勝数操作(外部セーブが必要)
};

static const BMPLIST_HEADER DebugListH = {
	NULL,					//表示文字データポインタ

	NULL,					//カーソル移動ごとのコールバック関数
	NULL,					//一列表示ごとのコールバック関数

	NULL,					//GF_BGL_BMPWINのポインタ

	NELEMS(DebugMenuList),	//リスト項目数
	9,						//表示最大項目数

	0,						//ラベル表示Ｘ座標
	8,						//項目表示Ｘ座標
	0,						//カーソル表示Ｘ座標
	0,						//表示Ｙ座標
/*
	FBMP_COL_BLACK,			//文字色
	FBMP_COL_WHITE,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
*/
	FBMP_COL_WHITE,			//文字色
	FBMP_COL_BLACK,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
	0,						//文字間隔Ｘ
	16,						//文字間隔Ｙ
	BMPLIST_LRKEY_SKIP,		//ページスキップタイプ
	FONT_SYSTEM,			//文字指定(本来は u8 だけど、そんなに作らないと思うので)
	0						//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
};


//==============================================================================================
//
//	BMPウィンドウ
//
//==============================================================================================
enum{
	D_NOHARA_BMPWIN_FRAME	= GF_BGL_FRAME3_M,
	D_NOHARA_BMPWIN_PX1		= 1,
	D_NOHARA_BMPWIN_PY1		= 1,
	D_NOHARA_BMPWIN_SX		= 16,
	D_NOHARA_BMPWIN_SY		= 20,
	D_NOHARA_BMPWIN_PL		= FLD_SYSFONT_PAL,
	D_NOHARA_BMPWIN_CH		= 1,
};

static const BMPWIN_DAT	DebugNoharaWinData = {
	D_NOHARA_BMPWIN_FRAME,					//ウインドウ使用フレーム
	D_NOHARA_BMPWIN_PX1,D_NOHARA_BMPWIN_PY1,//ウインドウ領域の左上のX,Y座標（キャラ単位で指定）
	D_NOHARA_BMPWIN_SX,	D_NOHARA_BMPWIN_SY,	//ウインドウ領域のX,Yサイズ（キャラ単位で指定）
	D_NOHARA_BMPWIN_PL,						//ウインドウ領域のパレットナンバー
	D_NOHARA_BMPWIN_CH						//ウインドウキャラ領域の開始キャラクタナンバー
};


//==============================================================================================
//
//	プログラム
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	デバックメニュー呼び出し(fld_debug.c)
 *
 * @param	fsys	FIELDSYS_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
void DebugNoharaMenuInit( FIELDSYS_WORK* fsys )
{
	int i;
	BMPLIST_HEADER list_h;
	D_NOHARA_WORK* wk;

	wk = (D_NOHARA_WORK*)TCB_GetWork( PMDS_taskAdd(DebugNoharaMenuMain, sizeof(D_NOHARA_WORK), 0, HEAPID_BASE_DEBUG) );

	wk->seq				= 0;
	wk->sel				= 0;
	wk->work			= 0;
	wk->wave_buf_flag	= 0;								//波形格納バッファを確保したフラグOFF
	wk->waveout_flag	= 0;								//鳴き声再生中フラグOFF
	wk->fsys			= fsys;

	GF_BGL_BmpWinAddEx( wk->fsys->bgl, &wk->bmpwin[0], &DebugNoharaWinData );	//ビットマップ追加

	wk->menulist = BMP_MENULIST_Create( NELEMS(DebugMenuList), HEAPID_BASE_DEBUG );


	wk->wordset = WORDSET_Create( HEAPID_BASE_DEBUG );

	wk->msgman = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG,
								NARC_msg_debug_nohara_dat, HEAPID_BASE_DEBUG);

	for( i=0; i < NELEMS(DebugMenuList); i++ ){
		BMP_MENULIST_AddArchiveString( wk->menulist, wk->msgman,
										DebugMenuList[i].str_id, DebugMenuList[i].param );
	}

	list_h			= DebugListH;
	list_h.list		= wk->menulist;
	list_h.win		= &wk->bmpwin[0];
	wk->lw			= BmpListSet( &list_h, 0, 0, HEAPID_BASE_DEBUG );

	GF_BGL_BmpWinOn( &wk->bmpwin[0] );
	return;
}

//--------------------------------------------------------------
/**
 * @brief	デバックメニューメイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void DebugNoharaMenuMain( TCB_PTR tcb, void * work )
{
	u32	ret;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	switch( wk->seq ){
	case 0:
		ret = BmpListMain( wk->lw );

		switch( ret ){
		case BMPLIST_NULL:
			break;
		case BMPLIST_CANCEL:
			TcbBmpDel( tcb, work );				//TCBBMP開放

			//波形再生用チャンネルを開放する
			Snd_DebugNormalChannelFree();

			break;
		default:
			wk->sel = ret;
			wk->seq++;
			break;
		};

		//BMPリストのリスト位置、カーソル位置を取得
		BmpListPosGet( wk->lw, &wk->list_bak, &wk->cursor_bak );
		break;

	case 1:
		{
			voidFunc func = (voidFunc)wk->sel;
			TCB_ChangeFunc( tcb, (void*)func );	//TCBの動作関数切り替え
		}
		break;

	};

	return;
}

//--------------------------------------------------------------
/**
 * @brief	TCB,BMP開放
 *
 * @param	tcb		TCB_PTR型
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void TcbBmpDel( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	MSGMAN_Delete( wk->msgman );
	WORDSET_Delete( wk->wordset );

#if 0
	//波形格納バッファを確保したフラグONだったら
	if( wk->wave_buf_flag == 1 ){
		sys_FreeMemoryEz( wk->wave_buf );	//バッファ開放
	}
#endif

	BmpDel( tcb );						//BMP開放
	PMDS_taskDel( tcb );				//TCB開放
	FieldSystemProc_SeqHoldEnd();
	return;
}

//--------------------------------------------------------------
/**
 * @brief	BMP開放
 *
 * @param	tcb		TCB_PTR型
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void BmpDel( TCB_PTR tcb )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)TCB_GetWork(tcb);

	//BMP
	BMP_MENULIST_Delete( wk->menulist );
	BmpListExit( wk->lw, &wk->list_bak, &wk->cursor_bak );
	GF_BGL_BmpWinOff( &wk->bmpwin[0] );
	GF_BGL_BmpWinDel( &wk->bmpwin[0] );
	return;
}

//--------------------------------------------------------------
/**
 * @brief	数字メッセージ表示
 *
 * @param	win_index	ビットマップINDEX
 * @param	num			数値
 * @param	x			表示位置X
 * @param	y			表示位置Y
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void NumMsgSet( D_NOHARA_WORK* wk, GF_BGL_BMPWIN* win, int num, u8 x, u8 y )
{
	STRBUF* tmp_buf	= STRBUF_Create( 12, HEAPID_BASE_DEBUG );
	STRBUF* tmp_buf2= STRBUF_Create( 12, HEAPID_BASE_DEBUG );

	MSGMAN_GetString( wk->msgman, msg_debug_nohara_num, tmp_buf );
	WORDSET_RegisterNumber(wk->wordset, 1, num, 4, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT);

	//登録された単語を使って文字列展開する
	WORDSET_ExpandStr( wk->wordset, tmp_buf2, tmp_buf );

	GF_STR_PrintSimple( win, FONT_SYSTEM, tmp_buf2, x, y, MSG_NO_PUT, NULL );

	STRBUF_Delete( tmp_buf );
	STRBUF_Delete( tmp_buf2 );
	return;
}


//==============================================================================================
//
//	01	逆再生関連
//
//==============================================================================================
static void D_Nohara_01_Main( TCB_PTR tcb, void * work );

//extern BOOL Snd_ArcStrmStart( u16 no );

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_01( TCB_PTR tcb, void * work )
{
	int i;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;
	wk->seq		= 0;
	wk->count	= 0;
	wk->work	= MONSNO_HUSIGIDANE;

#if 0
	Snd_CtrlBgmFlagSet( 1 );
	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
#endif

	//BGMを止める
	Snd_Stop();

#if 0
	Snd_PerapVoiceWazaParamGet( 0 );
	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
#endif

#if 0
	//ストリーム再生実験
	//Snd_ArcStrmStart( STRM_PV001 );
	Snd_ArcStrmStart( STRM_PV009 );
	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
#endif

#if 0
	//フラグチェック
	OS_Printf( "===============\n " );
	OS_Printf( "===============\n " );
	for( i=0; i < 10 ;i++ ){
		OS_Printf( "flag %d = %d\n ", i ,CheckEventFlag( wk->fsys, i) );
	}
	TcbBmpDel( tcb, work );		//TCBBMP開放
#else
	TCB_ChangeFunc( tcb, D_Nohara_01_Main );	//TCBの動作関数切り替え
#endif
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_01_Main( TCB_PTR tcb, void * work )
{
	int ret,flag;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	flag = 0;	//書き換えフラグ

	if( wk->waveout_flag == 0 ){					//鳴き声再生中フラグOFFだったら

		//鳴き声再生
		if( sys.trg == PAD_BUTTON_A ){
			wk->waveout_flag = 1;					//鳴き声再生中フラグON
			return;		//注意！
		}

		if( (sys.repeat == PAD_KEY_UP) || (sys.cont == PAD_KEY_RIGHT) ){
			flag = 1;
			wk->work++;
			if( wk->work >= MONSNO_MAX ){
				wk->work = 1;
			}
		}

		if( (sys.repeat == PAD_KEY_DOWN) || (sys.cont == PAD_KEY_LEFT) ){
			flag = 1;
			wk->work--;
			if( wk->work <= 0 ){
				wk->work = (MONSNO_MAX - 1);
			}
		}

		//書き換えフラグが立っていたら
		if( flag == 1 ){
			//指定範囲を塗りつぶし
			GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*11, 0, 8*6, 8*2 );

			//ポケモンナンバー表示
			NumMsgSet( wk, &wk->bmpwin[0], wk->work, 8*11, 2 );
			GF_BGL_BmpWinOn( &wk->bmpwin[0] );
		}

		//終了
		if( sys.cont == PAD_BUTTON_B ){
			TcbBmpDel( tcb, work );				//TCBBMP開放
		}

		return;	//注意！
	}


	switch( wk->seq ){
	case 0:
		//PLATINUM_MERGE 暫定フォルム指定追加
		ret = Snd_PMVoicePlay( wk->work ,0 );		//通常再生
		//OS_Printf( "normal play = %d\n", ret );
		wk->seq++;
		break;
	case 1:
		if( Snd_PMVoicePlayCheck() == 0 ){
			wk->count = 0;
			wk->seq++;
		}
		break;
	case 2:
		wk->count++;
		if( wk->count >= 15 ){							//間を入れる
			Snd_WaveOutAllocChannel( WAVEOUT_CH_NORMAL );//波形再生用チャンネルを確保する
			ret = Snd_WaveOutStartReverse( wk->work, 60, 64, WAVEOUT_CH_NORMAL,
											HEAPID_BASE_DEBUG );//逆再生
			//OS_Printf( "reverse play = %d\n", ret );
			wk->count = 0;
			wk->seq++;
		}
		break;
	case 3:
		//波形再生中かチェック
		if( Snd_WaveOutIsPlaying( WAVEOUT_CH_NORMAL ) == FALSE ){
			Snd_WaveOutStopReverse( WAVEOUT_CH_NORMAL );//逆再生停止buf開放
			Snd_WaveOutFreeChannel( WAVEOUT_CH_NORMAL );//波形再生用チャンネルを開放する
			wk->seq = 0;
			wk->count = 0;
			wk->waveout_flag = 0;				//鳴き声再生中フラグOFF
		}
		break;
	};

	return;
}


//==============================================================================================
//
//	02	リバーブ関連
//
//==============================================================================================
static void D_Nohara_02_Main( TCB_PTR tcb, void * work );

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_02( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;
	wk->seq		= 0;
	wk->count	= 0;
	wk->work	= 0;
	TCB_ChangeFunc( tcb, D_Nohara_02_Main );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_02_Main( TCB_PTR tcb, void * work )
{
	int flag;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	flag = 0;	//書き換えフラグ

	if( (sys.repeat == PAD_KEY_UP) || (sys.cont == PAD_KEY_RIGHT) ){
		flag = 1;
		wk->work++;
		if( wk->work >= 64 ){
			wk->work = 0;
		}
	}

	if( (sys.repeat == PAD_KEY_DOWN) || (sys.cont == PAD_KEY_LEFT) ){
		flag = 1;
		wk->work--;
		if( wk->work < 0 ){
			wk->work = 63;
		}
	}

	//書き換えフラグが立っていたら
	if( flag == 1 ){
		if( Snd_CaptureStartReverb( wk->work ) == FALSE ){
			OS_Printf( "リバーブ失敗！\n" );
		}

		//指定範囲を塗りつぶし
		GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*7, 8*2,
								8*8, 8*2 );

		//リバーブ値表示
		NumMsgSet( wk, &wk->bmpwin[0], wk->work, 8*7, 8*2 );
		GF_BGL_BmpWinOn( &wk->bmpwin[0] );
	}

	//終了
	if( sys.cont == PAD_BUTTON_B ){
		TcbBmpDel( tcb, work );		//TCBBMP開放
	}

	return;
}


//==============================================================================================
//
//	04	FIELD BGM 音量関連
//
//==============================================================================================
static void D_Nohara_04_Main( TCB_PTR tcb, void * work );

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_04( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;
	wk->seq		= 0;
	wk->count	= 0;
	wk->work	= 0;
	TCB_ChangeFunc( tcb, D_Nohara_04_Main );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_04_Main( TCB_PTR tcb, void * work )
{
	int flag;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	flag = 0;	//書き換えフラグ

	if( (sys.repeat == PAD_KEY_UP) || (sys.cont == PAD_KEY_RIGHT) ){
		flag = 1;
		wk->work++;
		if( wk->work >= 128 ){
			wk->work = 0;
		}
	}

	if( (sys.repeat == PAD_KEY_DOWN) || (sys.cont == PAD_KEY_LEFT) ){
		flag = 1;
		wk->work--;
		if( wk->work < 0 ){
			wk->work = 127;
		}
	}

	//書き換えフラグが立っていたら
	if( flag == 1 ){
		Snd_PlayerSetInitialVolume( SND_HANDLE_FIELD, wk->work );

		//指定範囲を塗りつぶし
		GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*11, 8*6, 8*8, 8*2 );

		//音量表示
		NumMsgSet( wk, &wk->bmpwin[0], wk->work, 8*11, 8*6 );
		GF_BGL_BmpWinOn( &wk->bmpwin[0] );
	}

	//終了
	if( sys.cont == PAD_BUTTON_B ){
		TcbBmpDel( tcb, work );		//TCBBMP開放
	}

	return;
}


//==============================================================================================
//
//	05	鳴き声パターン関連
//
//==============================================================================================
static void D_Nohara_05_Main( TCB_PTR tcb, void * work );

static const struct{
	u32  str_id;
	u32  param;
}DebugMenuList05[] = {
	{ msg_debug_nohara_05_01, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_02, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_03, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_04, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_05, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_06, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_07, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_08, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_09, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_10, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_11, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_12, (u32)D_Nohara_05_Main },
	{ msg_debug_nohara_05_13, (u32)D_Nohara_05_Main },
};

static const BMPLIST_HEADER ListH05 = {
	NULL,					//表示文字データポインタ
	NULL,					//カーソル移動ごとのコールバック関数
	NULL,					//一列表示ごとのコールバック関数

	NULL,					//GF_BGL_BMPWINのポインタ

	NELEMS(DebugMenuList05),//リスト項目数
	9,						//表示最大項目数

	0,						//ラベル表示Ｘ座標
	8,						//項目表示Ｘ座標
	0,						//カーソル表示Ｘ座標
	0,						//表示Ｙ座標
/*
	FBMP_COL_BLACK,			//文字色
	FBMP_COL_WHITE,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
*/
	FBMP_COL_WHITE,			//文字色
	FBMP_COL_BLACK,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
	0,						//文字間隔Ｘ
	16,						//文字間隔Ｙ
	BMPLIST_LRKEY_SKIP,		//ページスキップタイプ
	FONT_SYSTEM,			//文字指定(本来は u8 だけど、そんなに作らないと思うので)
	0						//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
};

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_05( TCB_PTR tcb, void * work )
{
	int i;
	BMPLIST_HEADER list_h;
	GF_BGL_BMPWIN* win;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	BmpDel( tcb );								//BMP開放

	wk->seq		= 0;
	wk->sel		= 0;
	wk->count	= MONSNO_HUSIGIDANE;

	GF_BGL_BmpWinAddEx( wk->fsys->bgl, &wk->bmpwin[0], &DebugNoharaWinData );	//ビットマップ追加

	wk->menulist = BMP_MENULIST_Create( NELEMS(DebugMenuList05), HEAPID_BASE_DEBUG );

	for( i=0; i < NELEMS(DebugMenuList05); i++ ){
		BMP_MENULIST_AddArchiveString( wk->menulist, wk->msgman,
										DebugMenuList05[i].str_id, DebugMenuList05[i].param );
	}

	list_h			= ListH05;
	list_h.list		= wk->menulist;
	list_h.win		= &wk->bmpwin[0];
	wk->lw			= BmpListSet( &list_h, 0, 0, HEAPID_BASE_DEBUG );

	GF_BGL_BmpWinOn( &wk->bmpwin[0] );

	//TCB_ChangeFunc( tcb, D_Nohara_05_Main );	//TCBの動作関数切り替え
	TCB_ChangeFunc( tcb, DebugNoharaMenuMain );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_05_Main( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	if( sys.cont & PAD_BUTTON_L ){
		wk->count--;
	}else if( sys.cont & PAD_BUTTON_R ){
		wk->count++;
	}

	//ポケモン鳴き声パターンセット
	//monsno,pan,vol,ptn
	Snd_PMVoicePlayEx( (wk->cursor_bak+wk->list_bak),
						wk->count, 0, 127,
						//MONSNO_HUSIGIDANE, 0, 127,
						//MONSNO_HIKOZARU, (gf_rand() % 127), 127,
						HEAPID_BASE_DEBUG ,0 ); //PLATINUM_MERGE 暫定フォルム指定追加

	wk->seq = 0;
	TCB_ChangeFunc( tcb, DebugNoharaMenuMain );		//TCBの動作関数切り替え
	return;
}


//==============================================================================================
//
//	06	出力エフェクト関連
//
//==============================================================================================
static void D_Nohara_06_Main( TCB_PTR tcb, void * work );

static const struct{
	u32  str_id;
	u32  param;
}DebugMenuList06[] = {
	{ msg_debug_nohara_06_01, (u32)D_Nohara_06_Main },
	{ msg_debug_nohara_06_02, (u32)D_Nohara_06_Main },
	{ msg_debug_nohara_06_03, (u32)D_Nohara_06_Main },
	{ msg_debug_nohara_06_04, (u32)D_Nohara_06_Main },
};

static const BMPLIST_HEADER ListH06 = {
	NULL,					//表示文字データポインタ
	NULL,					//カーソル移動ごとのコールバック関数
	NULL,					//一列表示ごとのコールバック関数

	NULL,					//GF_BGL_BMPWINのポインタ

	NELEMS(DebugMenuList06),//リスト項目数
	5,						//表示最大項目数

	0,						//ラベル表示Ｘ座標
	8,						//項目表示Ｘ座標
	0,						//カーソル表示Ｘ座標
	0,						//表示Ｙ座標
/*
	FBMP_COL_BLACK,			//文字色
	FBMP_COL_WHITE,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
*/
	FBMP_COL_WHITE,			//文字色
	FBMP_COL_BLACK,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
	0,						//文字間隔Ｘ
	16,						//文字間隔Ｙ
	BMPLIST_LRKEY_SKIP,		//ページスキップタイプ
	FONT_SYSTEM,			//文字指定(本来は u8 だけど、そんなに作らないと思うので)
	0						//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
};

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_06( TCB_PTR tcb, void * work )
{
	int i;
	BMPLIST_HEADER list_h;
	GF_BGL_BMPWIN* win;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	BmpDel( tcb );								//BMP開放

	//Snd_CaptureCreateThread();

	wk->seq		= 0;
	wk->sel		= 0;
	wk->count	= 0;

	GF_BGL_BmpWinAddEx( wk->fsys->bgl, &wk->bmpwin[0], &DebugNoharaWinData );	//ビットマップ追加

	wk->menulist = BMP_MENULIST_Create( NELEMS(DebugMenuList06), HEAPID_BASE_DEBUG );

	for( i=0; i < NELEMS(DebugMenuList06); i++ ){
		BMP_MENULIST_AddArchiveString( wk->menulist, wk->msgman,
										DebugMenuList06[i].str_id, DebugMenuList06[i].param );
	}

	list_h			= ListH06;
	list_h.list		= wk->menulist;
	list_h.win		= &wk->bmpwin[0];
	wk->lw			= BmpListSet( &list_h, 0, 0, HEAPID_BASE_DEBUG );

	GF_BGL_BmpWinOn( &wk->bmpwin[0] );

	//TCB_ChangeFunc( tcb, D_Nohara_06_Main );	//TCBの動作関数切り替え
	TCB_ChangeFunc( tcb, DebugNoharaMenuMain );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_06_Main( TCB_PTR tcb, void * work )
{
	NNSSndCaptureOutputEffectType stereo_mono;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	switch( wk->cursor_bak ){
	case 1:
		stereo_mono = NNS_SND_CAPTURE_OUTPUT_EFFECT_MONO;
		break;
	case 2:
		stereo_mono = NNS_SND_CAPTURE_OUTPUT_EFFECT_SURROUND;
		break;
	case 3:
		stereo_mono = NNS_SND_CAPTURE_OUTPUT_EFFECT_HEADPHONE;
		break;
	default:
		stereo_mono = NNS_SND_CAPTURE_OUTPUT_EFFECT_NORMAL;
		break;
	}

	Snd_CaptureStartOutputEffect( stereo_mono );
	//Snd_CaptureChangeOutputEffect( stereo_mono );

	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
}


//==============================================================================================
//
//	07	マイク関連
//
//==============================================================================================
static void D_Nohara_07_Main( TCB_PTR tcb, void * work );

static const struct{
	u32  str_id;
	u32  param;
}DebugMenuList07[] = {
	{ msg_debug_nohara_07_01, (u32)D_Nohara_07_Main },
	{ msg_debug_nohara_07_02, (u32)D_Nohara_07_Main },
	{ msg_debug_nohara_07_03, (u32)D_Nohara_07_Main },
	{ msg_debug_nohara_07_04, (u32)D_Nohara_07_Main },
	{ msg_debug_nohara_07_05, (u32)D_Nohara_07_Main },
	{ msg_debug_nohara_07_06, (u32)D_Nohara_07_Main },
};

static const BMPLIST_HEADER ListH07 = {
	NULL,					//表示文字データポインタ
	NULL,					//カーソル移動ごとのコールバック関数
	NULL,					//一列表示ごとのコールバック関数

	NULL,					//GF_BGL_BMPWINのポインタ

	NELEMS(DebugMenuList07),//リスト項目数
	6,						//表示最大項目数

	0,						//ラベル表示Ｘ座標
	8,						//項目表示Ｘ座標
	0,						//カーソル表示Ｘ座標
	0,						//表示Ｙ座標
/*
	FBMP_COL_BLACK,			//文字色
	FBMP_COL_WHITE,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
*/
	FBMP_COL_WHITE,			//文字色
	FBMP_COL_BLACK,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
	0,						//文字間隔Ｘ
	16,						//文字間隔Ｙ
	BMPLIST_LRKEY_SKIP,		//ページスキップタイプ
	FONT_SYSTEM,			//文字指定(本来は u8 だけど、そんなに作らないと思うので)
	0						//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
};

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_07( TCB_PTR tcb, void * work )
{
	int i;
	BMPLIST_HEADER list_h;
	GF_BGL_BMPWIN* win;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	BmpDel( tcb );								//BMP開放

#if 0
	//バッファ確保
	wk->wave_buf = sys_AllocMemory( HEAPID_BASE_DEBUG, WAVE_SAMPLE );
	if( wk->wave_buf == NULL ){
		GF_ASSERT( (0) && "メモリ確保に失敗しました！" );
	}
	memset( wk->wave_buf, 0, WAVE_SAMPLE );
#endif

	//波形再生用チャンネルを確保する
	Snd_WaveOutAllocChannel( WAVEOUT_CH_NORMAL );

	wk->seq				= 0;
	wk->sel				= 0;
	wk->count			= 0;
	wk->wave_buf_flag	= 1;					//波形格納バッファを確保したフラグON

	GF_BGL_BmpWinAddEx( wk->fsys->bgl, &wk->bmpwin[0], &DebugNoharaWinData );	//ビットマップ追加

	wk->menulist = BMP_MENULIST_Create( NELEMS(DebugMenuList07), HEAPID_BASE_DEBUG );

	for( i=0; i < NELEMS(DebugMenuList07); i++ ){
		BMP_MENULIST_AddArchiveString( wk->menulist, wk->msgman,
										DebugMenuList07[i].str_id, DebugMenuList07[i].param );
	}

	list_h			= ListH07;
	list_h.list		= wk->menulist;
	list_h.win		= &wk->bmpwin[0];
	wk->lw			= BmpListSet( &list_h, 0, 0, HEAPID_BASE_DEBUG );

	GF_BGL_BmpWinOn( &wk->bmpwin[0] );

	//TCB_ChangeFunc( tcb, D_Nohara_07_Main );	//TCBの動作関数切り替え
	TCB_ChangeFunc( tcb, DebugNoharaMenuMain );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_07_Main( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	switch( wk->cursor_bak ){
	case 0:
		//録音開始
		Snd_PerapVoiceRecStart();
		break;

	case 1:
		//録音停止
		Snd_PerapVoiceRecStop();
		break;

	case 2:
		//自分のぺラップの録音したデータを再生
		Snd_PerapVoicePlay( SaveData_GetPerapVoice(wk->fsys->savedata), PM_MALE, 127, 64 );
		break;

	case 3:
		Snd_PMVoiceStop( 0 );
		break;

	case 4:
		//録音したデータを自分のぺラップデータにコピー
		Snd_PerapVoiceDataSave( SaveData_GetPerapVoice(wk->fsys->savedata) );
		break;

	default:
		//起動
		EventSet_Script( wk->fsys, SCRID_PERAP, NULL );
		TcbBmpDel( tcb, work );		//TCBBMP開放
		return;
	};

	wk->seq = 0;
	TCB_ChangeFunc( tcb, DebugNoharaMenuMain );		//TCBの動作関数切り替え
	return;
}


//==============================================================================================
//
//	08	FIELD TEMPO 音量関連
//
//==============================================================================================
static void D_Nohara_08_Main( TCB_PTR tcb, void * work );

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_08( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;
	wk->seq		= 0;
	wk->count	= 0;
	wk->work	= 256;
	TCB_ChangeFunc( tcb, D_Nohara_08_Main );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_08_Main( TCB_PTR tcb, void * work )
{
	int flag;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	flag = 0;	//書き換えフラグ

	if( (sys.repeat == PAD_KEY_UP) || (sys.cont == PAD_KEY_RIGHT) ){
		flag = 1;
		wk->work++;
		if( wk->work >= 512 ){
			wk->work = 64;
		}
	}

	if( (sys.repeat == PAD_KEY_DOWN) || (sys.cont == PAD_KEY_LEFT) ){
		flag = 1;
		wk->work--;
		if( wk->work < 64 ){
			wk->work = 512;
		}
	}

	//書き換えフラグが立っていたら
	if( flag == 1 ){
		Snd_PlayerSetTempoRatio( SND_HANDLE_FIELD, wk->work );

		//指定範囲を塗りつぶし
		GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*11, 8*14, 8*8, 8*2 );

		//テンポ表示
		NumMsgSet( wk, &wk->bmpwin[0], wk->work, 8*11, 8*14 );
		GF_BGL_BmpWinOn( &wk->bmpwin[0] );
	}

	//終了
	if( sys.cont == PAD_BUTTON_B ){
		TcbBmpDel( tcb, work );		//TCBBMP開放
	}

	return;
}


//==============================================================================================
//
//	11	スクリプト実行関連
//
//==============================================================================================
static void D_Nohara_11_Main( TCB_PTR tcb, void * work );

static const struct{
	u32  str_id;
	u32  param;
}DebugMenuList11[] = {
	{ msg_debug_nohara_11_01, (u32)D_Nohara_11_Main },
	{ msg_debug_nohara_11_02, (u32)D_Nohara_11_Main },
	{ msg_debug_nohara_11_03, (u32)D_Nohara_11_Main },
};

static const BMPLIST_HEADER ListH11 = {
	NULL,					//表示文字データポインタ
	NULL,					//カーソル移動ごとのコールバック関数
	NULL,					//一列表示ごとのコールバック関数

	NULL,					//GF_BGL_BMPWINのポインタ

	NELEMS(DebugMenuList11),//リスト項目数
	10,						//表示最大項目数

	0,						//ラベル表示Ｘ座標
	8,						//項目表示Ｘ座標
	0,						//カーソル表示Ｘ座標
	0,						//表示Ｙ座標
/*
	FBMP_COL_BLACK,			//文字色
	FBMP_COL_WHITE,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
*/
	FBMP_COL_WHITE,			//文字色
	FBMP_COL_BLACK,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
	0,						//文字間隔Ｘ
	16,						//文字間隔Ｙ
	BMPLIST_LRKEY_SKIP,		//ページスキップタイプ
	FONT_SYSTEM,			//文字指定(本来は u8 だけど、そんなに作らないと思うので)
	0						//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
};

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_11( TCB_PTR tcb, void * work )
{
	int i;
	BMPLIST_HEADER list_h;
	GF_BGL_BMPWIN* win;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	BmpDel( tcb );								//BMP開放

	wk->seq				= 0;
	wk->sel				= 0;
	wk->count			= 0;

	GF_BGL_BmpWinAddEx( wk->fsys->bgl, &wk->bmpwin[0], &DebugNoharaWinData );	//ビットマップ追加

	wk->menulist = BMP_MENULIST_Create( NELEMS(DebugMenuList11), HEAPID_BASE_DEBUG );

	for( i=0; i < NELEMS(DebugMenuList11); i++ ){
		BMP_MENULIST_AddArchiveString( wk->menulist, wk->msgman,
										DebugMenuList11[i].str_id, DebugMenuList11[i].param );
	}

	list_h			= ListH11;
	list_h.list		= wk->menulist;
	list_h.win		= &wk->bmpwin[0];
	wk->lw			= BmpListSet( &list_h, 0, 0, HEAPID_BASE_DEBUG );

	GF_BGL_BmpWinOn( &wk->bmpwin[0] );

	//TCB_ChangeFunc( tcb, D_Nohara_11_Main );	//TCBの動作関数切り替え
	TCB_ChangeFunc( tcb, DebugNoharaMenuMain );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_11_Main( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	switch( wk->cursor_bak ){
	case 0:
		//C07の倉庫の鍵出現させる
//		SpScriptStart( wk->fsys, SCRID_DEBUG_C07_SOUKONOKAGI ); //070419 金銀へ以降の為無効化
		break;

	case 1:
		//３つの湖イベント開始
//		SpScriptStart( wk->fsys, SCRID_DEBUG_L01_L02_L03_LAKE ); //070419 金銀へ以降の為無効化
		break;

	case 2:
		//ポケセン地下ストッパー削除、ともだち手帳イベント無効
//		SpScriptStart( wk->fsys, SCRID_DEBUG_PC_UG );		//070419 金銀へ以降の為無効化
		break;

	default:
		//EventSet_Script( wk->fsys, SCRID_TANPAN_01, NULL );
		TcbBmpDel( tcb, work );		//TCBBMP開放
		return;
	};

	wk->seq = 0;
	TCB_ChangeFunc( tcb, DebugNoharaMenuMain );		//TCBの動作関数切り替え
	return;
}


//==============================================================================================
//
//	14	サウンドエフェクト
//
//==============================================================================================
static void D_Nohara_14_Main( TCB_PTR tcb, void * work );

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_14( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;
	wk->seq		= 0;
	wk->count	= 0;
	wk->count2	= 0;
	wk->work	= 0;
	Snd_CaptureStartEffect();
	TCB_ChangeFunc( tcb, D_Nohara_14_Main );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_14_Main( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	int flag = 0;

	wk = (D_NOHARA_WORK*)work;

	//再生
	//if( sys.trg == PAD_BUTTON_A ){
	//	Snd_CaptureStartEffect();
	//	return;
	//}

	if( (sys.repeat == PAD_KEY_UP) || (sys.cont == PAD_KEY_RIGHT) ){
		flag = 1;
		wk->work++;
		if( wk->work > 8 ){
			wk->work = 8;
		}
	}

	if( (sys.repeat == PAD_KEY_DOWN) || (sys.cont == PAD_KEY_LEFT) ){
		flag = 1;
		wk->work--;
		if( wk->work < 0 ){
			wk->work = 0;
		}
	}

	//書き換えフラグが立っていたら
	if( flag == 1 ){
		//指定範囲を塗りつぶし
		GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*11, 0, 8*6, 8*2 );

		//ポケモンナンバー表示
		NumMsgSet( wk, &wk->bmpwin[0], wk->work, 8*11, 2 );
		GF_BGL_BmpWinOn( &wk->bmpwin[0] );

		//エフェクトレベルセット
		Snd_CaptureEffectLevel( wk->work );
	}

	//停止、終了
	if( sys.cont == PAD_BUTTON_B ){
		Snd_CaptureStopEffect();
		TcbBmpDel( tcb, work );				//TCBBMP開放
		return;
	}

	return;
}


//==============================================================================================
//
//	15	鳴き声波形関連
//
//==============================================================================================
static void D_Nohara_15_Main( TCB_PTR tcb, void * work );

u32 now_tick;									//現在のティック数

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_15( TCB_PTR tcb, void * work )
{
	int i;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;
	wk->seq		= 0;
	wk->count	= 0;
	wk->work	= MONSNO_HUSIGIDANE;
	TCB_ChangeFunc( tcb, D_Nohara_15_Main );	//TCBの動作関数切り替え
	return;
}

u8 test_buf[9];	//
const SNDWaveData* pw_data;
//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_15_Main( TCB_PTR tcb, void * work )
{
	int ret,flag,i;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	flag = 0;	//書き換えフラグ

	if( wk->waveout_flag == 0 ){					//鳴き声再生中フラグOFFだったら

		//鳴き声再生
		if( sys.trg == PAD_BUTTON_A ){
			wk->waveout_flag = 1;					//鳴き声再生中フラグON
			return;		//注意！
		}

		if( (sys.repeat == PAD_KEY_UP) || (sys.cont == PAD_KEY_RIGHT) ){
			flag = 1;
			wk->work++;
			if( wk->work >= MONSNO_MAX ){
				wk->work = 1;
			}
		}

		if( (sys.repeat == PAD_KEY_DOWN) || (sys.cont == PAD_KEY_LEFT) ){
			flag = 1;
			wk->work--;
			if( wk->work <= 0 ){
				wk->work = (MONSNO_MAX - 1);
			}
		}

		//書き換えフラグが立っていたら
		if( flag == 1 ){
			//指定範囲を塗りつぶし
			GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*11, 0, 8*6, 8*2 );

			//ポケモンナンバー表示
			NumMsgSet( wk, &wk->bmpwin[0], wk->work, 8*11, 2 );
			GF_BGL_BmpWinOn( &wk->bmpwin[0] );
		}

		//終了
		if( sys.cont == PAD_BUTTON_B ){
			TcbBmpDel( tcb, work );				//TCBBMP開放
		}

		return;	//注意！
	}

	switch( wk->seq ){
	case 0:
#if 1
		now_tick = 0;
		//Snd_ZukanWaveDataSet( wk->work );							//波形データのアドレス取得
		pw_data = Snd_ZukanWaveDataSet( wk->work );					//波形データのアドレス取得
		OS_Printf( "pw_data size = %d\n", Snd_WaveDataSampleSizeGet( pw_data ) );
		//Snd_DebugWaveDataPut( 0, 1000 );							//波形データ表示

		for( i=0; i < 9 ;i++ ){
			test_buf[i] = 0;
		}

		//PLATINUM_MERGE 暫定フォルム指定追加
		ret = Snd_PMVoicePlay( wk->work ,0);							//通常再生

		//音程操作
		if( sys.cont & PAD_BUTTON_L ){
			//Snd_PlayerSetTrackPitch( SND_HANDLE_PMVOICE, 0xffff, -64 * 12 );
			Snd_PlayerSetTrackPitch( SND_HANDLE_PMVOICE, 0xffff, 64 * 12 );
		}
#endif

		//pw_data = Snd_ZukanWaveDataSet( wk->work );					//波形データのアドレス取得
		//Snd_PMVoicePlayPtn_ZukanChorus( 1, 0 );
		//Snd_PMVoicePlayPtn_ZukanChorus( 1, 80 );

		wk->seq++;
		break;
	case 1:
		if( Snd_PMVoicePlayCheck() == 0 ){
			wk->count = 0;
			wk->seq++;
		}else{
			{
				u32 tmp,old_tick;

#if 0
				old_tick = now_tick;								//退避
				//now_tick = Snd_ZukanPlayerGetTick();				//ティック数取得
				now_tick = Snd_PlayerGetSampleTick( SND_HANDLE_PMVOICE, pw_data );	//ティック数取得

				//240(今) - 180(前) = 60(差)
				//60 / 2 = 30
				//240 - 30 = 210(中間)
				tmp = (now_tick - ((now_tick-old_tick) / 2));
				Snd_DebugWaveDataPut( pw_data, tmp, tmp+1 );					//前回との中間位置

				Snd_DebugWaveDataPut( pw_data, now_tick, now_tick+1 );		//現在の位置
				Snd_DebugWaveLevelGet( now_tick );					//レベル
#endif

				//レベル取得
				Snd_ZukanWaveLevelSet_New( pw_data, test_buf, 9, 0 );
			}
		}
		break;
	case 2:
		wk->seq = 0;
		wk->count = 0;
		wk->waveout_flag = 0;				//鳴き声再生中フラグOFF
		break;
	};

	return;
}


//==============================================================================================
//
//	17	バッジフラグセット
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_17( TCB_PTR tcb, void * work )
{
	int i;
	D_NOHARA_WORK* wk = (D_NOHARA_WORK*)work;
	MYSTATUS* my = SaveData_GetMyStatus( wk->fsys->savedata );

	for( i=0; i < 16; i++ ){
		MyStatus_SetBadgeFlag( my, i );
	}

	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
}


//==============================================================================================
//
//	18	隠しアイテム検索
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_18( TCB_PTR tcb, void * work )
{
	int i,count;
	D_NOHARA_WORK* wk = (D_NOHARA_WORK*)work;
	MYSTATUS* my = SaveData_GetMyStatus( wk->fsys->savedata );
	HIDE_ITEM_LIST* p = HideItem_CreateList( wk->fsys, HEAPID_BASE_DEBUG );

	count = 0;

	while( 1 ){
		if( p[count].response == HIDE_LIST_RESPONSE_NONE ){
			if( count == 0 ){
				OS_Printf( "隠しアイテムは見つかりませんでした！\n" );
			}
			break;
		}

		OS_Printf( "\nresponse = %d\n", p[count].response );
		OS_Printf( "gx = %d\n", p[count].gx );
		OS_Printf( "gz = %d\n", p[count].gz );
		count++;
	};

	sys_FreeMemoryEz( p );

	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
}


//==============================================================================================
//
//	19	隠しアイテム検索
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_19( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk = (D_NOHARA_WORK*)work;

	Snd_CaptureIsActive();

	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
}


//==============================================================================================
//
//	21	デバックジャンプ
//
//==============================================================================================
static void D_Nohara_21_Main( TCB_PTR tcb, void * work );

typedef struct{
	u32 zone_id;
	u32 num;
	u32 x;
	u32 z;
}DEBUG_JUMP_WORK;

static const DEBUG_JUMP_WORK debug_jump_work[] = {
	{ ZONE_ID_D35R0102,	3502,	14,		24 },			//ロケット団アジト
	{ ZONE_ID_D39R0102,	3902,	19,		12 },			//岩落とす
	{ ZONE_ID_D39R0103,	3903,	20,		15 },			//岩落ちた先
	{ ZONE_ID_D27R0107,	2717,	8,		9 },			//灯台
	{ ZONE_ID_D49R0101,	49,		24,		10 },			//ポケスロン外
	//環境音
	{ ZONE_ID_T27,		27,		401,	162 },			//○せせらぎテスト
	{ ZONE_ID_T20,		20,		700,	400 },			//○なみテスト・○風車
	{ ZONE_ID_D15R0101,	1501,	16,		20 },			//○柱テスト
	{ ZONE_ID_W41,		41,		219,	331 },			//○うずしおテスト
	{ ZONE_ID_D38R0101,	3801,	45,		25 },			//○たきテスト
	{ ZONE_ID_T30GYM0101,3001,	14,		7  },			//○溶岩テスト
	{ ZONE_ID_D24R0206, 2426,	6,		3  },			//○風テスト
	{ ZONE_ID_P01R0102, 102,	18,		23 },			//○汽笛テスト
	{ ZONE_ID_D35R0103, 3513,	21,		18 },			//○モーターテスト(発電所など)
	{ ZONE_ID_R48,		48,		101,	340 },			//○鐘テスト
	{ ZONE_ID_P01R0307, 137,	45,		16 },			//○エンジンテスト(船内)
	//足音
	{ ZONE_ID_D17R1101,	1711,	11,		10 },			//○落ち葉テスト
	{ ZONE_ID_D36R0101,	3601,	52,		54 },			//○枝テスト
	{ ZONE_ID_R29,		29,		585,	407 },			//○短い草テスト
	{ ZONE_ID_T21,		21,		539,	400 },			//○砂浜テスト
	{ ZONE_ID_T22,		22,		465,	246 },			//硬い地面テスト
	{ ZONE_ID_T26GYM0101,2601,	6,		17 },			//○金属テスト
	{ ZONE_ID_D22R0101,	2201,	39,		28 },			//○長い草テスト
	{ ZONE_ID_R39R0201,	3902,	3,		8 },			//○牧場の寝わらテスト
	{ ZONE_ID_D25R0101,	2501,	3,		3 },			//○岩テスト
	{ ZONE_ID_P01R0102, 102,	16,		21 },			//アサギの港テスト
	{ ZONE_ID_R34,		34,		370,	431 },			//○波打ち際、水溜りテスト
	{ ZONE_ID_T22,		22,		488,	247 },			//つり橋テスト
	//
	{ ZONE_ID_D45R0101,	4501,	27,		12 },			//滝の環境音のボリュームレベル確認
};
#define DEBUG_JUMP_WORK_MAX	( NELEMS(debug_jump_work) )

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_21( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;
	wk->seq		= 0;
	wk->count	= 0;
	wk->work	= 0;
	TCB_ChangeFunc( tcb, D_Nohara_21_Main );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_21_Main( TCB_PTR tcb, void * work )
{
	int flag;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	flag = 0;	//書き換えフラグ

	if( (sys.repeat == PAD_KEY_UP) || (sys.cont == PAD_KEY_RIGHT) ){
		flag = 1;
		wk->work++;
		if( wk->work >= DEBUG_JUMP_WORK_MAX ){
			wk->work = 0;
		}
	}

	if( (sys.repeat == PAD_KEY_DOWN) || (sys.cont == PAD_KEY_LEFT) ){
		flag = 1;
		wk->work--;
		if( wk->work < 0 ){
			wk->work = (DEBUG_JUMP_WORK_MAX - 1);
		}
	}

	//書き換えフラグが立っていたら
	if( flag == 1 ){
		//指定範囲を塗りつぶし
		GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*7, 8*2,
								8*8, 8*2 );

		//値表示
		NumMsgSet( wk, &wk->bmpwin[0], debug_jump_work[wk->work].num, 8*7, 8*2 );
		GF_BGL_BmpWinOn( &wk->bmpwin[0] );
	}

	//ジャンプ
	if( sys.trg == PAD_BUTTON_A ){

		EventSet_EasyMapChange( wk->fsys, debug_jump_work[wk->work].zone_id, DOOR_ID_JUMP_CODE,
							debug_jump_work[wk->work].x , debug_jump_work[wk->work].z, DIR_DOWN );

		TcbBmpDel( tcb, work );		//TCBBMP開放
		return;
	}

	//終了
	if( sys.cont == PAD_BUTTON_B ){
		TcbBmpDel( tcb, work );		//TCBBMP開放
		return;
	}

	return;
}


//==============================================================================================
//
//	22	ポケッチ波形テスト
//
//==============================================================================================
static void D_Nohara_22_Main( TCB_PTR tcb, void * work );
static void Snd_DebugWaveBufWrite( u32 no );

static s8 d_sWaveBuffer[ 64 ] ATTRIBUTE_ALIGN(32);	//波形格納バッファ

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_22( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;
	wk->seq		= 0;
	wk->count	= 0;
	wk->work	= 0;

	//波形再生用チャンネルを確保する
	Snd_WaveOutAllocChannel( WAVEOUT_CH_NORMAL );

	TCB_ChangeFunc( tcb, D_Nohara_22_Main );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_22_Main( TCB_PTR tcb, void * work )
{
	int flag;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	flag = 0;	//書き換えフラグ


	switch( wk->seq ){
	case 0:
		//呼び出すパターンを切り替える
		if( sys.trg & PAD_KEY_UP ){
			Snd_DebugWaveBufWrite( 0 );
			wk->seq++;
		}else if( sys.trg & PAD_KEY_DOWN ){
			Snd_DebugWaveBufWrite( 1 );
			wk->seq++;
		}else if( sys.trg & PAD_KEY_RIGHT ){
			Snd_DebugWaveBufWrite( 2 );
			wk->seq++;
		}else if( sys.trg & PAD_KEY_LEFT ){
			Snd_DebugWaveBufWrite( 3 );
			wk->seq++;
		}

		//終了
		if( sys.cont == PAD_BUTTON_B ){
			//波形再生用チャンネルを開放する
			Snd_DebugNormalChannelFree();

			TcbBmpDel( tcb, work );		//TCBBMP開放
			return;
		}

		break;

	case 1:
		//波形再生
		{
			WAVEOUT_WORK waveout_wk;

			waveout_wk.handle			= Snd_WaveOutHandleGet(WAVEOUT_CH_NORMAL);//波形再生ハンドル
			waveout_wk.format			= NNS_SND_WAVE_FORMAT_PCM8;//波形データフォーマット
			waveout_wk.dataaddr			= &d_sWaveBuffer[0];//波形データの先頭アドレス
			waveout_wk.loopFlag			= TRUE;					//ループフラグ
			waveout_wk.loopStartSample	= 0;						//ループ開始サンプル位置
			waveout_wk.samples			= 64;				//波形データのサンプル数
			//waveout_wk.samples		= WAVE_SAMPLE;				//波形データのサンプル数
			waveout_wk.sampleRate		= 16000;					//波形データのサンプリングレート
			waveout_wk.volume			= 127;						//音量
			waveout_wk.speed			= 32768;					//再生スピード
			//waveout_wk.speed			= 32768*3;					//再生スピード
			//waveout_wk.speed			= 32768/3;					//再生スピード
			waveout_wk.pan				= 64;						//パン(0-127)

			Snd_WaveOutStart( &waveout_wk, WAVEOUT_CH_NORMAL );		//波形再生
		}
		wk->count = 0;
		wk->seq++;
		break;

	case 2:
		wk->count++;

		if( wk->count == 16 ){					//フレーム数なので注意！
			Snd_WaveOutSetSpeed( WAVEOUT_CH_NORMAL, (32768 * 2) );
		}

		if( wk->count == 24 ){					//フレーム数なので注意！
			Snd_WaveOutSetSpeed( WAVEOUT_CH_NORMAL, (32768 / 2) );
		}

		if( wk->count >= 32 ){					//フレーム数なので注意！
			Snd_WaveOutStop( WAVEOUT_CH_NORMAL );	//波形停止
			wk->seq = 0;
		}
		break;
	};

	return;
}

//--------------------------------------------------------------
/**
 * @brief	適当な波形を書き込む
 *
 * @param	no		パターン
 *
 * @retval	none
 */
//--------------------------------------------------------------
#define TEST_START	(0)
#define TEST_ADD	(64)
//#define TEST_LOOP	(40)
#define TEST_LOOP	(1)

static void Snd_DebugWaveBufWrite( u32 no )
{
	u8 add;
	int i,j;

	switch( no ){

	case 0:

		//「■」

		for( j=0; j < TEST_LOOP ;j++ ){

			add = TEST_ADD * j;

			for( i=0+add; i < 32+add ;i++ ){
				d_sWaveBuffer[i] = 120;
			}
			for( i=32+add; i < 64+add ;i++ ){
				d_sWaveBuffer[i] = -120;
			}
		}
		break;

	case 1:

		//「■」

		for( j=0; j < TEST_LOOP ;j++ ){

			add = TEST_ADD * j;

			for( i=0+add; i < 10+add ;i++ ){
				d_sWaveBuffer[i] = 0;
			}
			for( i=10+add; i < 20+add ;i++ ){
				d_sWaveBuffer[i] = 120;
			}
			for( i=20+add; i < 30+add ;i++ ){
				d_sWaveBuffer[i] = 0;
			}
			for( i=30+add; i < 40+add ;i++ ){
				d_sWaveBuffer[i] = -120;
				}
			for( i=40+add; i < 50+add ;i++ ){
				d_sWaveBuffer[i] = 0;
			}
			for( i=50+add; i < 64+add ;i++ ){
				d_sWaveBuffer[i] = 120;
			}
		}

	case 2:

		//「▲」
		//マイナスなし

		for( j=0; j < TEST_LOOP ;j++ ){

			add = TEST_ADD * j;

			d_sWaveBuffer[0+add] = 0;
			d_sWaveBuffer[1+add] = 4;
			d_sWaveBuffer[2+add] = 8;
			d_sWaveBuffer[3+add] = 12;
			d_sWaveBuffer[4+add] = 16;
			d_sWaveBuffer[5+add] = 20;
			d_sWaveBuffer[6+add] = 24;
			d_sWaveBuffer[7+add] = 28;
			d_sWaveBuffer[8+add] = 32;
			d_sWaveBuffer[9+add] = 36;
			d_sWaveBuffer[10+add] = 40;
			d_sWaveBuffer[11+add] = 44;
			d_sWaveBuffer[12+add] = 48;
			d_sWaveBuffer[13+add] = 52;
			d_sWaveBuffer[14+add] = 56;
			d_sWaveBuffer[15+add] = 60;
			d_sWaveBuffer[16+add] = 64;
			d_sWaveBuffer[17+add] = 68;
			d_sWaveBuffer[18+add] = 72;
			d_sWaveBuffer[19+add] = 76;
			d_sWaveBuffer[20+add] = 80;
			d_sWaveBuffer[21+add] = 84;
			d_sWaveBuffer[22+add] = 88;
			d_sWaveBuffer[23+add] = 92;
			d_sWaveBuffer[24+add] = 96;
			d_sWaveBuffer[25+add] = 100;
			d_sWaveBuffer[26+add] = 104;
			d_sWaveBuffer[27+add] = 108;
			d_sWaveBuffer[28+add] = 112;
			d_sWaveBuffer[29+add] = 116;
			d_sWaveBuffer[30+add] = 120;
			d_sWaveBuffer[31+add] = 124;
			d_sWaveBuffer[32+add] = 128;
			d_sWaveBuffer[33+add] = 124;
			d_sWaveBuffer[34+add] = 120;
			d_sWaveBuffer[35+add] = 116;
			d_sWaveBuffer[36+add] = 112;
			d_sWaveBuffer[37+add] = 108;
			d_sWaveBuffer[38+add] = 104;
			d_sWaveBuffer[39+add] = 100;
			d_sWaveBuffer[40+add] = 96;
			d_sWaveBuffer[41+add] = 92;
			d_sWaveBuffer[42+add] = 88;
			d_sWaveBuffer[43+add] = 84;
			d_sWaveBuffer[44+add] = 80;
			d_sWaveBuffer[45+add] = 76;
			d_sWaveBuffer[46+add] = 72;
			d_sWaveBuffer[47+add] = 68;
			d_sWaveBuffer[48+add] = 64;
			d_sWaveBuffer[49+add] = 60;
			d_sWaveBuffer[50+add] = 56;
			d_sWaveBuffer[51+add] = 52;
			d_sWaveBuffer[52+add] = 48;
			d_sWaveBuffer[53+add] = 44;
			d_sWaveBuffer[54+add] = 40;
			d_sWaveBuffer[55+add] = 36;
			d_sWaveBuffer[56+add] = 32;
			d_sWaveBuffer[57+add] = 28;
			d_sWaveBuffer[58+add] = 24;
			d_sWaveBuffer[59+add] = 20;
			d_sWaveBuffer[60+add] = 16;
			d_sWaveBuffer[61+add] = 12;
			d_sWaveBuffer[62+add] = 8;
			d_sWaveBuffer[63+add] = 4;
		};

		break;

	case 3:

		//「▲」
		//マイナスあり

		for( j=0; j < TEST_LOOP ;j++ ){

			add = TEST_ADD * j;

			d_sWaveBuffer[0+add] = -127;
			d_sWaveBuffer[1+add] = -119;
			d_sWaveBuffer[2+add] = -111;
			d_sWaveBuffer[3+add] = -103;
			d_sWaveBuffer[4+add] = -95;
			d_sWaveBuffer[5+add] = -87;
			d_sWaveBuffer[6+add] = -79;
			d_sWaveBuffer[7+add] = -71;
			d_sWaveBuffer[8+add] = -63;
			d_sWaveBuffer[9+add] = -55;
			d_sWaveBuffer[10+add] = -47;
			d_sWaveBuffer[11+add] = -39;
			d_sWaveBuffer[12+add] = -31;
			d_sWaveBuffer[13+add] = -23;
			d_sWaveBuffer[14+add] = -15;
			d_sWaveBuffer[15+add] = -7;
			d_sWaveBuffer[16+add] = 1;
			d_sWaveBuffer[17+add] = 9;
			d_sWaveBuffer[18+add] = 17;
			d_sWaveBuffer[19+add] = 25;
			d_sWaveBuffer[20+add] = 33;
			d_sWaveBuffer[21+add] = 41;
			d_sWaveBuffer[22+add] = 49;
			d_sWaveBuffer[23+add] = 57;
			d_sWaveBuffer[24+add] = 65;
			d_sWaveBuffer[25+add] = 73;
			d_sWaveBuffer[26+add] = 81;
			d_sWaveBuffer[27+add] = 89;
			d_sWaveBuffer[28+add] = 97;
			d_sWaveBuffer[29+add] = 105;
			d_sWaveBuffer[30+add] = 113;
			d_sWaveBuffer[31+add] = 121;
			d_sWaveBuffer[32+add] = 127;
			d_sWaveBuffer[33+add] = 121;
			d_sWaveBuffer[34+add] = 113;
			d_sWaveBuffer[35+add] = 105;
			d_sWaveBuffer[36+add] = 97;
			d_sWaveBuffer[37+add] = 89;
			d_sWaveBuffer[38+add] = 81;
			d_sWaveBuffer[39+add] = 73;
			d_sWaveBuffer[40+add] = 65;
			d_sWaveBuffer[41+add] = 57;
			d_sWaveBuffer[42+add] = 49;
			d_sWaveBuffer[43+add] = 41;
			d_sWaveBuffer[44+add] = 33;
			d_sWaveBuffer[45+add] = 25;
			d_sWaveBuffer[46+add] = 17;
			d_sWaveBuffer[47+add] = 9;
			d_sWaveBuffer[48+add] = 1;
			d_sWaveBuffer[49+add] = -7;
			d_sWaveBuffer[50+add] = -15;
			d_sWaveBuffer[51+add] = -23;
			d_sWaveBuffer[52+add] = -31;
			d_sWaveBuffer[53+add] = -39;
			d_sWaveBuffer[54+add] = -47;
			d_sWaveBuffer[55+add] = -55;
			d_sWaveBuffer[56+add] = -63;
			d_sWaveBuffer[57+add] = -71;
			d_sWaveBuffer[58+add] = -79;
			d_sWaveBuffer[59+add] = -87;
			d_sWaveBuffer[60+add] = -95;
			d_sWaveBuffer[61+add] = -103;
			d_sWaveBuffer[62+add] = -111;
			d_sWaveBuffer[63+add] = -119;
		};

		break;

	default:
		break;
	};

	//テスト表示
	for( j=0; j < 64*10 ;j++ ){
		OS_Printf( "d_sWaveBuffer[%d] = %d\n", j, d_sWaveBuffer[j] );
	}

	return;
}


//==============================================================================================
//
//	25	BGMオフ
//
//==============================================================================================
extern void Snd_DebugBgmFlagSet( u8 sw );

//--------------------------------------------------------------
/**
 * @brief	BGMオフ
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_25( TCB_PTR tcb, void * work )
{
#ifdef PM_DEBUG
	Snd_DebugBgmFlagSet( 1 );
	Snd_Stop();
#endif

	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
}


//==============================================================================================
//
//	26	BGMオン
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	BGMオン
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_26( TCB_PTR tcb, void * work )
{
#ifdef PM_DEBUG
	u16 bgm_no;
	D_NOHARA_WORK* wk = (D_NOHARA_WORK*)work;

	Snd_DebugBgmFlagSet( 0 );

	//サウンドデータセット(シーンが変更されない時は何もしない)
	Snd_SceneSet( SND_SCENE_DUMMY );
	bgm_no = Snd_FieldBgmNoGet( wk->fsys, wk->fsys->location->zone_id );
	Snd_ZoneBgmSet(Snd_FieldBgmNoGetNonBasicBank(wk->fsys,wk->fsys->location->zone_id));//zone set

	Snd_FieldSceneDataSet( wk->fsys, bgm_no );		//SND_SCENE_FIELD + 環境音再生
#endif

	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
}


//==============================================================================================
//
//	27	ゲームボーイ切り替え
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	ゲームボーイ切り替え
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_27( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk = (D_NOHARA_WORK*)work;

	//アイテム使用した時の処理
	Snd_GameBoyItemUse();

	TcbBmpDel( tcb, work );		//TCBBMP開放
	return;
}







//--------------------------------------------------------------
/**
 * @brief	バイナリメッセージファイル読み込み、表示テスト
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_89(void)
{
#if 1
	return;
#else
	static u16 * pMsg = NULL;

	//debug_msg.datはcvsに登録していないので注意！
	pMsg = (u16 *)sys_LoadFile( HEAPID_BASE_DEBUG, "/data/script/debug_msg.dat" );
	FieldTalkWinPut();
	msg_no_print( pMsg );
	FieldTalkMsgStart( pMsg, 1 );					//第2引数=skip
	sys_FreeMemoryEz( pMsg );

	return;
#endif
}

//--------------------------------------------------------------
/**
 * @brief	トラックミュートテスト
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_72(void)
{
	Snd_PlayerSetTrackMute( SND_HANDLE_FIELD, ( (1 << 0) | (2 << 0) ), TRUE );
	return;
}


















//==============================================================================================
//
//
//
//==============================================================================================

static const struct{
	u32  str_id;
	u32  param;
}DebugMenuList2[] = {
	{ msg_debug_nohara_25, (u32)D_Nohara_25 },
	{ msg_debug_nohara_26, (u32)D_Nohara_26 },
};

static const BMPLIST_HEADER DebugListH2 = {
	NULL,					//表示文字データポインタ

	NULL,					//カーソル移動ごとのコールバック関数
	NULL,					//一列表示ごとのコールバック関数

	NULL,					//GF_BGL_BMPWINのポインタ

	NELEMS(DebugMenuList2),	//リスト項目数
	9,						//表示最大項目数

	0,						//ラベル表示Ｘ座標
	8,						//項目表示Ｘ座標
	0,						//カーソル表示Ｘ座標
	0,						//表示Ｙ座標
/*
	FBMP_COL_BLACK,			//文字色
	FBMP_COL_WHITE,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
*/
	FBMP_COL_WHITE,			//文字色
	FBMP_COL_BLACK,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
	0,						//文字間隔Ｘ
	16,						//文字間隔Ｙ
	BMPLIST_LRKEY_SKIP,		//ページスキップタイプ
	FONT_SYSTEM,			//文字指定(本来は u8 だけど、そんなに作らないと思うので)
	0						//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
};

//--------------------------------------------------------------
/**
 * @brief	BGMデバックメニュー呼び出し(fld_debug.c)
 *
 * @param	fsys	FIELDSYS_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
void DebugBgmMenuInit( FIELDSYS_WORK* fsys )
{
	int i;
	BMPLIST_HEADER list_h;
	D_NOHARA_WORK* wk;

	wk = (D_NOHARA_WORK*)TCB_GetWork( PMDS_taskAdd(DebugNoharaMenuMain, sizeof(D_NOHARA_WORK), 0, HEAPID_BASE_DEBUG) );

	wk->seq				= 0;
	wk->sel				= 0;
	wk->work			= 0;
	wk->wave_buf_flag	= 0;								//波形格納バッファを確保したフラグOFF
	wk->waveout_flag	= 0;								//鳴き声再生中フラグOFF
	wk->fsys			= fsys;

	GF_BGL_BmpWinAddEx( wk->fsys->bgl, &wk->bmpwin[0], &DebugNoharaWinData );	//ビットマップ追加

	wk->menulist = BMP_MENULIST_Create( NELEMS(DebugMenuList2), HEAPID_BASE_DEBUG );

	wk->wordset = WORDSET_Create( HEAPID_BASE_DEBUG );

	wk->msgman = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG,
								NARC_msg_debug_nohara_dat, HEAPID_BASE_DEBUG);

	for( i=0; i < NELEMS(DebugMenuList2); i++ ){
		BMP_MENULIST_AddArchiveString( wk->menulist, wk->msgman,
										DebugMenuList2[i].str_id, DebugMenuList2[i].param );
	}

	list_h			= DebugListH2;
	list_h.list		= wk->menulist;
	list_h.win		= &wk->bmpwin[0];
	wk->lw			= BmpListSet( &list_h, 0, 0, HEAPID_BASE_DEBUG );

	GF_BGL_BmpWinOn( &wk->bmpwin[0] );
	return;
}


//==============================================================================================
//
//	デバック「のはら」ではない所からの「デバックスクリプト」呼び出し
//
//==============================================================================================

static const struct{
	u32  str_id;
	u32  param;
}DebugMenuList3[] = {
	{ msg_debug_nohara_11, (u32)D_Nohara_11 },
};

static const BMPLIST_HEADER DebugListH3 = {
	NULL,					//表示文字データポインタ

	NULL,					//カーソル移動ごとのコールバック関数
	NULL,					//一列表示ごとのコールバック関数

	NULL,					//GF_BGL_BMPWINのポインタ

	NELEMS(DebugMenuList3),	//リスト項目数
	9,						//表示最大項目数

	0,						//ラベル表示Ｘ座標
	8,						//項目表示Ｘ座標
	0,						//カーソル表示Ｘ座標
	0,						//表示Ｙ座標
/*
	FBMP_COL_BLACK,			//文字色
	FBMP_COL_WHITE,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
*/
	FBMP_COL_WHITE,			//文字色
	FBMP_COL_BLACK,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
	0,						//文字間隔Ｘ
	16,						//文字間隔Ｙ
	BMPLIST_LRKEY_SKIP,		//ページスキップタイプ
	FONT_SYSTEM,			//文字指定(本来は u8 だけど、そんなに作らないと思うので)
	0						//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
};

//--------------------------------------------------------------
/**
 * @brief	BGMデバックメニュー呼び出し(fld_debug.c)
 *
 * @param	fsys	FIELDSYS_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
void DebugScriptMenuInit( FIELDSYS_WORK* fsys )
{
	int i;
	BMPLIST_HEADER list_h;
	D_NOHARA_WORK* wk;

	wk = (D_NOHARA_WORK*)TCB_GetWork( PMDS_taskAdd(DebugNoharaMenuMain, sizeof(D_NOHARA_WORK), 0, HEAPID_BASE_DEBUG) );

	wk->seq				= 0;
	wk->sel				= 0;
	wk->work			= 0;
	wk->wave_buf_flag	= 0;								//波形格納バッファを確保したフラグOFF
	wk->waveout_flag	= 0;								//鳴き声再生中フラグOFF
	wk->fsys			= fsys;

	GF_BGL_BmpWinAddEx( wk->fsys->bgl, &wk->bmpwin[0], &DebugNoharaWinData );	//ビットマップ追加

	wk->menulist = BMP_MENULIST_Create( NELEMS(DebugMenuList3), HEAPID_BASE_DEBUG );

	wk->wordset = WORDSET_Create( HEAPID_BASE_DEBUG );

	wk->msgman = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG,
								NARC_msg_debug_nohara_dat, HEAPID_BASE_DEBUG);

	for( i=0; i < NELEMS(DebugMenuList3); i++ ){
		BMP_MENULIST_AddArchiveString( wk->menulist, wk->msgman,
										DebugMenuList3[i].str_id, DebugMenuList3[i].param );
	}

	list_h			= DebugListH3;
	list_h.list		= wk->menulist;
	list_h.win		= &wk->bmpwin[0];
	wk->lw			= BmpListSet( &list_h, 0, 0, HEAPID_BASE_DEBUG );

	GF_BGL_BmpWinOn( &wk->bmpwin[0] );
	return;
}

//==============================================================================================
//
//	34	フロンティア関連(連勝数操作)
//
//==============================================================================================
static void D_Nohara_34_Main( TCB_PTR tcb, void * work );
static void D_Nohara_34_2_Main( TCB_PTR tcb, void * work );

enum{
	D34_PARAM_TOWER = 100,
	D34_PARAM_FACTORY,
	D34_PARAM_FACTORY_OPEN,
	D34_PARAM_STAGE,
	D34_PARAM_CASTLE,
	D34_PARAM_ROULETTE,
};

static const struct{
	u32  str_id;
	u32  param;
}DebugMenuList34[] = {
	//タワーのセットは色々違うので保留。。。(タワーはwifiマルチのみ対応しました)
	{ msg_debug_nohara_34_15, D34_PARAM_TOWER },		//タワー
	{ msg_debug_nohara_34_02, D34_PARAM_FACTORY },		//ファクトリー
	{ msg_debug_nohara_36,	  D34_PARAM_FACTORY_OPEN },	//ファクトリーオープン
	{ msg_debug_nohara_34_03, D34_PARAM_STAGE },		//ステージ
	{ msg_debug_nohara_34_04, D34_PARAM_CASTLE },		//キャッスル
	{ msg_debug_nohara_34_05, D34_PARAM_ROULETTE },		//ルーレット
};

//マイナスにした時の最大連勝数セット値
static const u16 frontier_num_max[] = {
	9996,			//タワー
	9996,			//ファクトリー
	9996,			//ファクトリーオープン
	9990,			//ステージ
	9996,			//キャッスル
	9996,			//ルーレット
};

enum{
	D34_PARAM_SINGLE = 0,
	D34_PARAM_DOUBLE,
	D34_PARAM_MULTI,
	D34_PARAM_WIFI_MULTI,
};

static const struct{
	u32  str_id;
	u32  param;
}DebugMenuList34_type[] = {
	{ msg_debug_nohara_34_11, D34_PARAM_SINGLE },		//シングル
	{ msg_debug_nohara_34_12, D34_PARAM_DOUBLE },		//ダブル
	{ msg_debug_nohara_34_13, D34_PARAM_MULTI },		//マルチ
	{ msg_debug_nohara_34_14, D34_PARAM_WIFI_MULTI },	//WIFIマルチ
};

static const BMPLIST_HEADER ListH34 = {
	NULL,					//表示文字データポインタ
	NULL,					//カーソル移動ごとのコールバック関数
	NULL,					//一列表示ごとのコールバック関数

	NULL,					//GF_BGL_BMPWINのポインタ

	//NELEMS(DebugMenuList34_type),//リスト項目数
	1,						//リスト項目数
	10,						//表示最大項目数

	0,						//ラベル表示Ｘ座標
	8,						//項目表示Ｘ座標
	0,						//カーソル表示Ｘ座標
	0,						//表示Ｙ座標

	FBMP_COL_WHITE,			//文字色
	FBMP_COL_BLACK,			//背景色
	FBMP_COL_BLK_SDW,		//文字影色
	0,						//文字間隔Ｘ
	16,						//文字間隔Ｙ
	BMPLIST_LRKEY_SKIP,		//ページスキップタイプ
	FONT_SYSTEM,			//文字指定(本来は u8 だけど、そんなに作らないと思うので)
	0						//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
};

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_34( TCB_PTR tcb, void * work )
{
	int i;
	BMPLIST_HEADER list_h;
	GF_BGL_BMPWIN* win;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	switch( wk->fro_seq ){

	//施設選択
	case 0:
		BmpDel( tcb );								//BMP開放
		GF_BGL_BmpWinAddEx( wk->fsys->bgl, &wk->bmpwin[0], &DebugNoharaWinData );	//BMP追加
		wk->menulist = BMP_MENULIST_Create( NELEMS(DebugMenuList34), HEAPID_BASE_DEBUG );
		for( i=0; i < NELEMS(DebugMenuList34); i++ ){
			BMP_MENULIST_AddArchiveString( wk->menulist, wk->msgman,
											DebugMenuList34[i].str_id, DebugMenuList34[i].param );
		}
		list_h			= ListH34;
		list_h.list		= wk->menulist;
		list_h.win		= &wk->bmpwin[0];
		list_h.count	= NELEMS(DebugMenuList34);
		wk->lw			= BmpListSet( &list_h, 0, 0, HEAPID_BASE_DEBUG );
		GF_BGL_BmpWinOn( &wk->bmpwin[0] );
		break;

	//バトルタイプ選択
	case 1:
		GF_BGL_BmpWinAddEx( wk->fsys->bgl, &wk->bmpwin[0], &DebugNoharaWinData );	//BMP追加
		wk->menulist = BMP_MENULIST_Create( NELEMS(DebugMenuList34_type), HEAPID_BASE_DEBUG );
		for( i=0; i < NELEMS(DebugMenuList34_type); i++ ){
			BMP_MENULIST_AddArchiveString( wk->menulist, wk->msgman,
									DebugMenuList34_type[i].str_id, DebugMenuList34_type[i].param );
		}
		list_h			= ListH34;
		list_h.list		= wk->menulist;
		list_h.win		= &wk->bmpwin[0];
		list_h.count	= NELEMS(DebugMenuList34_type);
		wk->lw			= BmpListSet( &list_h, 0, 0, HEAPID_BASE_DEBUG );
		GF_BGL_BmpWinOn( &wk->bmpwin[0] );
		break;

	};

	wk->fro_seq++;
	TCB_ChangeFunc( tcb, D_Nohara_34_Main );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_34_Main( TCB_PTR tcb, void * work )
{
	u32	ret;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	ret = BmpListMain( wk->lw );

	switch( ret ){

	case BMPLIST_NULL:
		break;

	case BMPLIST_CANCEL:
		TcbBmpDel( tcb, work );				//TCBBMP開放
		break;

	////////////////////////////////////////////////////////////////////
	case D34_PARAM_TOWER:
		wk->fro_type = D34_PARAM_TOWER;
		wk->fro_add  = 7;
		BmpDel( tcb );						//BMP開放
		TCB_ChangeFunc( tcb, D_Nohara_34 );	//TCBの動作関数切り替え
		break;

	case D34_PARAM_FACTORY:
		wk->fro_type = D34_PARAM_FACTORY;
		wk->fro_add  = 7;
		BmpDel( tcb );						//BMP開放
		TCB_ChangeFunc( tcb, D_Nohara_34 );	//TCBの動作関数切り替え
		break;

	case D34_PARAM_FACTORY_OPEN:
		wk->fro_type = D34_PARAM_FACTORY_OPEN;
		wk->fro_add  = 7;
		BmpDel( tcb );						//BMP開放
		TCB_ChangeFunc( tcb, D_Nohara_34 );	//TCBの動作関数切り替え
		break;

	case D34_PARAM_STAGE:
		wk->fro_type = D34_PARAM_STAGE;
		wk->fro_add  = 10;					//ステージは10連勝くぎり
		BmpDel( tcb );						//BMP開放
		TCB_ChangeFunc( tcb, D_Nohara_34 );	//TCBの動作関数切り替え
		break;

	case D34_PARAM_CASTLE:
		wk->fro_type = D34_PARAM_CASTLE;
		wk->fro_add  = 7;
		BmpDel( tcb );						//BMP開放
		TCB_ChangeFunc( tcb, D_Nohara_34 );	//TCBの動作関数切り替え
		break;

	case D34_PARAM_ROULETTE:
		wk->fro_type = D34_PARAM_ROULETTE;
		wk->fro_add  = 7;
		BmpDel( tcb );						//BMP開放
		TCB_ChangeFunc( tcb, D_Nohara_34 );	//TCBの動作関数切り替え
		break;

	////////////////////////////////////////////////////////////////////
	case D34_PARAM_SINGLE:
		wk->btl_type = D34_PARAM_SINGLE;
		TCB_ChangeFunc( tcb, D_Nohara_34_2_Main );	//TCBの動作関数切り替え
		break;

	case D34_PARAM_DOUBLE:
		wk->btl_type = D34_PARAM_DOUBLE;
		TCB_ChangeFunc( tcb, D_Nohara_34_2_Main );	//TCBの動作関数切り替え
		break;

	case D34_PARAM_MULTI:
		wk->btl_type = D34_PARAM_MULTI;
		TCB_ChangeFunc( tcb, D_Nohara_34_2_Main );	//TCBの動作関数切り替え
		break;

	case D34_PARAM_WIFI_MULTI:
		wk->btl_type = D34_PARAM_WIFI_MULTI;
		TCB_ChangeFunc( tcb, D_Nohara_34_2_Main );	//TCBの動作関数切り替え
		break;

	};

	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_34_2_Main( TCB_PTR tcb, void * work )
{
	int i;
	u8 buf8[4];
	u16 num,type,l_num,h_num;
	u32	ret,flag;
	D_NOHARA_WORK* wk;
	POKEMON_PARAM* poke;
	FACTORYSCORE* fa_score_sv;
	STAGESCORE* s_score_sv;
	CASTLESCORE* ca_score_sv;
	ROULETTESCORE* r_score_sv;
	FRONTIER_SAVEWORK * fr_sv;

	wk = (D_NOHARA_WORK*)work;
	fr_sv = SaveData_GetFrontier( wk->fsys->savedata );

	flag = 0;		//書き換えフラグ

	if( sys.trg == PAD_BUTTON_A ){

		switch( wk->fro_type ){
		////////////////////////////////////////////////////////////////////
		case D34_PARAM_TOWER:

			////////////////////
			//★WIFIマルチ限定！
			////////////////////

			//"7連勝(クリア)したかフラグ"書き出し
			FrontierRecord_Set(	fr_sv,
				FRID_TOWER_MULTI_WIFI_CLEAR_BIT,
				wk->friend_work, 1 );

			//"連勝数"書き出し(「次は27人目です」というように使う)
			FrontierRecord_Set(	fr_sv,
					FRID_TOWER_MULTI_WIFI_RENSHOU_CNT,
					wk->friend_work, wk->work );
			break;

		case D34_PARAM_FACTORY:
			fa_score_sv = SaveData_GetFactoryScore( wk->fsys->savedata );

			if( wk->btl_type == FACTORY_TYPE_WIFI_MULTI ){

				//"7連勝(クリア)したかフラグ"書き出し
				FrontierRecord_Set(	fr_sv,
					FRID_FACTORY_MULTI_WIFI_CLEAR_BIT,
					wk->friend_work, 1 );

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
						FactoryScr_GetWinRecordID(0,wk->btl_type),
						wk->friend_work, wk->work );
			}else{

				//"7連勝(クリア)したかフラグ"書き出し
				buf8[0] = 1;
				FACTORYSCORE_PutScoreData(	fa_score_sv, FACTORYSCORE_ID_CLEAR_FLAG,
											wk->btl_type, buf8 );

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
					FactoryScr_GetWinRecordID(0,wk->btl_type),	//LV50
					Frontier_GetFriendIndex(FactoryScr_GetWinRecordID(0,wk->btl_type)), wk->work );
			}
			break;

		case D34_PARAM_FACTORY_OPEN:
			fa_score_sv = SaveData_GetFactoryScore( wk->fsys->savedata );

			if( wk->btl_type == FACTORY_TYPE_WIFI_MULTI ){

				//"7連勝(クリア)したかフラグ"書き出し
				FrontierRecord_Set(	fr_sv,
					FRID_FACTORY_MULTI_WIFI_CLEAR_BIT,
					wk->friend_work, 1 );

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
						FactoryScr_GetWinRecordID(1,wk->btl_type),
						wk->friend_work, wk->work );
			}else{

				//"7連勝(クリア)したかフラグ"書き出し
				buf8[0] = 1;
				FACTORYSCORE_PutScoreData(	fa_score_sv, FACTORYSCORE_ID_CLEAR_FLAG,
											//wk->btl_type, buf8 );
											(1*FACTORY_TYPE_MAX)+wk->btl_type, buf8 );

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
					FactoryScr_GetWinRecordID(1,wk->btl_type),	//オープン
					Frontier_GetFriendIndex(FactoryScr_GetWinRecordID(1,wk->btl_type)), wk->work );
			}
			break;

		case D34_PARAM_STAGE:
			s_score_sv = SaveData_GetStageScore( wk->fsys->savedata );

			//先頭のポケモンにする
			poke = PokeParty_GetMemberPointer( SaveData_GetTemotiPokemon(wk->fsys->savedata), 0 );

			if( wk->btl_type == STAGE_TYPE_WIFI_MULTI ){

				//"7連勝(クリア)したかフラグ"書き出し
				FrontierRecord_Set(	fr_sv,
					FRID_STAGE_MULTI_WIFI_CLEAR_BIT,
					wk->friend_work, 1 );

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
					StageScr_GetWinRecordID(wk->btl_type),
					wk->friend_work, wk->work );

				//"連勝中のポケモンナンバー"書き出し
				FrontierRecord_Set(	fr_sv,
						StageScr_GetMonsNoRecordID(wk->btl_type),
						wk->friend_work,
						PokeParaGet(poke,ID_PARA_monsno,NULL) );
			}else{
				//"7連勝(クリア)したかフラグ"書き出し
				buf8[0] = 1;
				STAGESCORE_PutScoreData( s_score_sv, STAGESCORE_ID_CLEAR_FLAG, wk->btl_type,0,buf8);

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
					StageScr_GetWinRecordID(wk->btl_type),
					Frontier_GetFriendIndex(StageScr_GetWinRecordID(wk->btl_type)), wk->work );

				//"連勝中のポケモンナンバー"書き出し
				FrontierRecord_Set(	fr_sv,
						StageScr_GetMonsNoRecordID(wk->btl_type),
						Frontier_GetFriendIndex(StageScr_GetMonsNoRecordID(wk->btl_type)),
						PokeParaGet(poke,ID_PARA_monsno,NULL) );

#if 1
				//「???」は抜かす
				//"タイプごとのレベル"を書き換え
				for( i=0; i < (STAGE_TR_TYPE_MAX-1) ;i++ ){
					//StageScr_TypeLevelRecordSet(wk->fsys->savedata, wk->btl_type,
					Debug_StageScr_TypeLevelRecordSet(	wk->fsys->savedata, wk->btl_type, i );
				}
#endif
			}

#if 0
			//"連勝中のポケモンナンバー"書き出し
			FrontierRecord_Set(	fr_sv,
						StageScr_GetMonsNoRecordID(wk->btl_type),
						Frontier_GetFriendIndex(StageScr_GetMonsNoRecordID(wk->btl_type)),
						0 );

			//ここで0をセットしても、d32r0401.evの流れで、
			//クリア中の時は、同じポケモンで挑戦しているかチェックが走ってしまい、
			//情報がクリアされてしまう。
#endif

			break;

		case D34_PARAM_CASTLE:
			ca_score_sv = SaveData_GetCastleScore( wk->fsys->savedata );

			if( wk->btl_type == CASTLE_TYPE_WIFI_MULTI ){

				//"7連勝(クリア)したかフラグ"書き出し
				FrontierRecord_Set(	fr_sv,
					FRID_CASTLE_MULTI_WIFI_CLEAR_BIT,
					wk->friend_work, 1 );

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
						CastleScr_GetWinRecordID(wk->btl_type),
						wk->friend_work, wk->work );
			}else{

				//"7連勝(クリア)したかフラグ"書き出し
				buf8[0] = 1;
				CASTLESCORE_PutScoreData(	ca_score_sv, CASTLESCORE_ID_CLEAR_FLAG,
											wk->btl_type, 0, buf8 );

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
						CastleScr_GetWinRecordID(wk->btl_type),
						Frontier_GetFriendIndex(CastleScr_GetWinRecordID(wk->btl_type)), wk->work );
			}
			break;

		case D34_PARAM_ROULETTE:
			r_score_sv = SaveData_GetRouletteScore( wk->fsys->savedata );

			if( wk->btl_type == ROULETTE_TYPE_WIFI_MULTI ){

				//"7連勝(クリア)したかフラグ"書き出し
				FrontierRecord_Set(	fr_sv,
					FRID_ROULETTE_MULTI_WIFI_CLEAR_BIT,
					wk->friend_work, 1 );

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
					RouletteScr_GetWinRecordID(wk->btl_type),
					wk->friend_work, wk->work );
			}else{

				//"7連勝(クリア)したかフラグ"書き出し
				buf8[0] = 1;
				ROULETTESCORE_PutScoreData( r_score_sv, ROULETTESCORE_ID_CLEAR_FLAG,
											wk->btl_type, 0, buf8 );

				//"連勝数"書き出し(「次は27人目です」というように使う)
				FrontierRecord_Set(	fr_sv,
					RouletteScr_GetWinRecordID(wk->btl_type),
					Frontier_GetFriendIndex(RouletteScr_GetWinRecordID(wk->btl_type)), wk->work );
			}
			break;
		}

		return;
	};

	//Rボタンを押していると友達を選択
	if( sys.cont & PAD_BUTTON_R ){

		if( (sys.repeat & PAD_KEY_UP) || (sys.cont & PAD_KEY_RIGHT) ){
			flag = 1;

			wk->friend_work+=1;

			if( wk->friend_work >= 32 ){
				wk->friend_work = 0;
			}
		}

		if( (sys.repeat & PAD_KEY_DOWN) || (sys.cont & PAD_KEY_LEFT) ){
			flag = 1;

			wk->friend_work-=1;

			//マイナスにした時の最大連勝数セット値
			if( wk->friend_work < 0 ){
				wk->friend_work = 31;
			}
		}

	}else{

		if( (sys.repeat & PAD_KEY_UP) || (sys.cont & PAD_KEY_RIGHT) ){
			flag = 1;

			if( sys.cont & PAD_BUTTON_L ){
				wk->work+=1;
			}else{
				wk->work+=wk->fro_add;
			}

			if( wk->work >= 9999 ){
				wk->work = 0;
			}
		}

		if( (sys.repeat & PAD_KEY_DOWN) || (sys.cont & PAD_KEY_LEFT) ){
			flag = 1;

			if( sys.cont & PAD_BUTTON_L ){
				wk->work-=1;
			}else{
				wk->work-=wk->fro_add;
			}

			//マイナスにした時の最大連勝数セット値
			if( wk->work < 0 ){
				//wk->work = (9999 - 1);
				wk->work = frontier_num_max[ (wk->fro_type - D34_PARAM_TOWER) ];
			}
		}
	}

	//書き換えフラグが立っていたら
	if( flag == 1 ){
		//指定範囲を塗りつぶし
		//GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*11, 0, 8*6, 8*2 );
		GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*11, 0, 8*6, 8*4 );

		//数値表示
		NumMsgSet( wk, &wk->bmpwin[0], wk->work, 8*11, 2 );

		//数値表示(友達)
		NumMsgSet( wk, &wk->bmpwin[0], wk->friend_work, 8*11, 8*2+2 );

		GF_BGL_BmpWinOn( &wk->bmpwin[0] );
	}

	//終了
	if( sys.cont == PAD_BUTTON_B ){
		TcbBmpDel( tcb, work );				//TCBBMP開放
	}

	return;
}

//==============================================================================================
//
//	41	ステージ連勝数操作関連
//
//==============================================================================================
static void D_Nohara_41_Main( TCB_PTR tcb, void * work );
static void StageRenshouSet( D_NOHARA_WORK* wk, u16 start_no, u16 end_no );

//--------------------------------------------------------------
/**
 * @brief	初期化
 *
 * @param	none
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_41( TCB_PTR tcb, void * work )
{
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;
	wk->seq		= 0;
	wk->count	= 0;
	wk->work	= 0;
	TCB_ChangeFunc( tcb, D_Nohara_41_Main );	//TCBの動作関数切り替え
	return;
}

//--------------------------------------------------------------
/**
 * @brief	メイン
 *
 * @param	tcb		TCB_PTR型
 * @param	work	ワーク
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void D_Nohara_41_Main( TCB_PTR tcb, void * work )
{
	LOAD_RESULT load_result;
	SAVE_RESULT save_result;
	FRONTIER_EX_SAVEDATA* fes;
	int flag;
	D_NOHARA_WORK* wk;
	wk = (D_NOHARA_WORK*)work;

	flag = 0;	//書き換えフラグ

	if( (sys.repeat == PAD_KEY_UP) || (sys.cont == PAD_KEY_RIGHT) ){
		flag = 1;
		wk->work++;
		if( wk->work > MONSNO_END ){
			wk->work = 1;
		}
	}

	if( (sys.repeat == PAD_KEY_DOWN) || (sys.cont == PAD_KEY_LEFT) ){
		flag = 1;
		wk->work--;
		if( wk->work < 1 ){
			wk->work = MONSNO_END;
		}
	}

	//書き換えフラグが立っていたら
	if( flag == 1 ){
		//指定範囲を塗りつぶし
		GF_BGL_BmpWinFill( &wk->bmpwin[0], FBMP_COL_BLACK, 8*7, 8*2,
								8*8, 8*2 );

		//モンスターナンバー表示
		NumMsgSet( wk, &wk->bmpwin[0], wk->work, 8*7, 8*2 );
		GF_BGL_BmpWinOn( &wk->bmpwin[0] );
	}

	//終了(1匹対象)
	if( sys.trg == PAD_BUTTON_A ){
		StageRenshouSet( wk, wk->work, (wk->work+1) );
		TcbBmpDel( tcb, work );		//TCBBMP開放
		return;
	}

	//終了(10匹対象)
	if( sys.trg == PAD_BUTTON_X ){
		//StageRenshouSet( wk, wk->work, (wk->work+10) );			//MONSNO_ENDチェックが必要
		StageRenshouSet( wk, 1, (10+1) );
		TcbBmpDel( tcb, work );		//TCBBMP開放
		return;
	}

	//終了(100匹対象)
	if( sys.trg == PAD_BUTTON_Y ){
		//StageRenshouSet( wk, wk->work, (wk->work+100) );			//MONSNO_ENDチェックが必要
		StageRenshouSet( wk, 1, (100+1) );
		TcbBmpDel( tcb, work );		//TCBBMP開放
		return;
	}

	//終了(全て対象)
	if( sys.trg == PAD_BUTTON_START ){
		//アルセウスは挑戦出来ないし、終端いきすぎは怖いので、ほぼ全てのポケモンにしている
		//StageRenshouSet( wk, 1, (MONSNO_END+1) );
		StageRenshouSet( wk, 1, MONSNO_END );
		TcbBmpDel( tcb, work );		//TCBBMP開放
		return;
	}

	//終了
	if( sys.cont == PAD_BUTTON_B ){
		TcbBmpDel( tcb, work );		//TCBBMP開放
	}

	return;
}

static void StageRenshouSet( D_NOHARA_WORK* wk, u16 start_no, u16 end_no )
{
	LOAD_RESULT load_result;
	SAVE_RESULT save_result;
	FRONTIER_EX_SAVEDATA* fes;
	int flag,i;

	fes = FrontierEx_Load( wk->fsys->savedata, HEAPID_WORLD, &load_result );
	if( load_result != LOAD_RESULT_OK ){
		//
	}else{

		for( i=start_no; i < end_no ;i++ ){

			//Debug_FrontierEx_StageRenshou_Set( fes, FREXID_STAGE_RENSHOU_SINGLE, wk->work, 9999 );
			Debug_FrontierEx_StageRenshou_Set( fes, FREXID_STAGE_RENSHOU_SINGLE, i, 500 );

			//OS_Printf( "num = %d\n", FrontierEx_StageRenshou_Get(	wk->fsys->savedata,fes,
			//														FREXID_STAGE_RENSHOU_SINGLE,
			//														wk->work) );
		}

#if 1
		//フィールド動作モデルのセーブ
		Field_SaveFieldObj( wk->fsys );

		// ポケッチ関連データのセーブ
		Field_SendPoketchInfo( wk->fsys, POKETCH_SEND_SAVE, 0 );

		//位置を引っ張る
		wk->fsys->location->grid_x = Player_NowGPosXGet( wk->fsys->player );
		wk->fsys->location->grid_z = Player_NowGPosZGet( wk->fsys->player );
		wk->fsys->location->door_id = DOOR_ID_JUMP_CODE;
		wk->fsys->location->dir = Player_DirGet( wk->fsys->player );
#endif

		//外部セーブを呼ばれないと反映しないので、このデバック微妙かも。。。
		save_result = FrontierEx_Save(wk->fsys->savedata, fes);
	}

	if( fes != NULL ){
		sys_FreeMemoryEz(fes);
	}

	return;
}

//--------------------------------------------------------------------------------------------
/**
 * タイプレベルのレコードをセット(fssc_stage_sub.cにある関数で呼べないのでコピペでもってきた)
 *
 * @param	wk
 *
 * @return	"レコード"
 *
 */
//--------------------------------------------------------------------------------------------
static void Debug_StageScr_TypeLevelRecordSet( SAVEDATA* sv, u8 type, u8 csr_pos )
{
	u8 offset;
	u8 param;
	u8 set_num,total;
	u16 l_num,h_num;

	//total = 0xaa;		//10101010(10挑戦済み)
	//total = 0x99;		//10011001(10挑戦前)
	//total = 0x88;		//10001000(9)
	total = 0x00;		//00000000(0)

#if 0
	switch( csr_pos ){
	case 0:
		total = 0x01;
		break;

	case 1:
		total = 0x01;
		break;

	case 2:
		total = 0x23;
		break;

	case 3:
		total = 0x23;
		break;

	case 4:
		total = 0x45;
		break;

	case 5:
		total = 0x45;
		break;

	case 6:
		total = 0x67;
		break;

	case 7:
		total = 0x67;
		break;

	case 8:
		total = 0x89;
		break;

	case 9:
		total = 0x89;
		break;

	};
#endif

	FrontierRecord_Set(	SaveData_GetFrontier(sv),
					StageScr_GetTypeLevelRecordID(type,csr_pos),
					Frontier_GetFriendIndex(StageScr_GetTypeLevelRecordID(type,csr_pos)), total );
	return;
}

